package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.UploadFileUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/admin/common")
@Slf4j
public class UploadFileController {
    @Autowired
    private UploadFileUtil uploadFileUtil;
    @PostMapping("/upload")
    @ApiOperation(value = "文件上传")
    public Result<String> upload(MultipartFile file){
        log.info("文件上传：{}",file);
        try{
            String filePath = uploadFileUtil.uploadFile(file);
            System.out.println("文件路径为：" + filePath);
            return Result.success(filePath);
        }catch (Exception e){
            e.printStackTrace();
        }
        return Result.error("文件上传失败");
    }
}
